package com.lxblyw.dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import com.lxblyw.entity.Message;
import com.lxblyw.util.DBHelp;
import com.lxblyw.util.RowMapper;

public class MessageDao {

	private DBHelp<Message> dbhelp = new DBHelp<Message>();
	private class MessageRowMapper implements RowMapper<Message> {

		public Message mapperRow(ResultSet rs) throws SQLException {
			Message msg = new Message();
			msg.setId(rs.getString("id"));
			msg.setContent(rs.getString("content"));
			msg.setCreatetime(rs.getString("createtime"));
			msg.setEmployeeid(rs.getString("employeeid"));
			msg.setProjectid(rs.getString("projectid"));
			return msg;
		}
		
		
		
	}
	public List<Message> findByProjectId(String id) {
		String sql = "select * from t_message where projectid = ? order by createtime desc";
		return dbhelp.executeQueryForList(sql, new MessageRowMapper(), id);
	}
	public void save(Message msg) {
		String sql = "insert into t_message(id,content,createtime,employeeid,projectid) values(?,?,?,?,?)";
		dbhelp.executeSQL(sql, msg.getId(),msg.getContent(),msg.getCreatetime(),msg.getEmployeeid(),msg.getProjectid());
	}

}
